<div class="row">
	<div class="col-lg-12">
		<h1 class="site-h1" style="background-color:#FFFFFF;">
			【${tenant.tenantname!''}】用户列表<#if userList??>（${userList.totalElements!''}）</#if>
			<div class="ukefu-bt-text-content" style="position: absolute;right: 80px;top: 3px;">
				<form class="layui-form" name="search" action="/admin/multitenant/user/index.html" method="get" style="float: left;">
					<input type="hidden" name="tenantcode" value="${tenantcode!''}">
					<input type="hidden" name="p" value="${p+1}">
					<div class="layui-form-item">
						<div class="layui-inline">
							<div class="layui-input-inline">
								<input type="text" name="q" value="${q!''}" style="height: 30px;line-height: 30px;margin-top: 4px;border: 1px solid #32c24d;"
									placeholder="请输入查询条件" autocomplete="off" class="layui-input">
								<i class="layui-icon" onclick="search.submit()" style="position: absolute;cursor: pointer;right: 3px;top: 4px;font-size: 20px;color:#32c24d;">&#xe615;</i>
							</div>
						</div>
					</div>
				</form>
			</div>
			<span style="float:right;">
				<button class="layui-btn layui-btn-sm green" href="/admin/multitenant/user/add.html?tenantcode=${tenantcode!''}" data-toggle="ajax" data-width="750" data-height="450" data-title="创建新用户">
					创建新用户
				</button>
			</span>
		</h1>
		<div class="row" style="padding:5px;">
			<div class="col-lg-12">
				<table class="layui-table" lay-skin="line">
				  <colgroup>
						<col width="29%">
						<col width="10%">
						<col width="15%">
						<col width="15%">
						<col width="10%">
						<#if models?? && models["callcenter"]?? && models["callcenter"] == true>
						<col width="7%">
						</#if>
						<col width="7%">
						<col width="8%">
						<col width="1%">
						<col>
				  </colgroup>
				  <thead>
				  <#if userList?? && userList.content?? && userList.content?size gt 0>
					<tr>
					  <th>用户</th>
					  <th>姓名</th>
					  <th>电子邮件</th>
					  <th>手机</th>
					  <th>多媒体</th>
					  <#if models?? && models["callcenter"]?? && models["callcenter"] == true>
					  <th>呼叫中心</th>
					  </#if>
					  <th>管理员</th>
					  <th>访客数</th>
					  <th style="white-space:nowrap;" nowrap="nowrap">操作</th>
					</tr> 
					</#if>
				  </thead>
				  <tbody>
					<#if userList?? && userList.content?? && userList.content?size gt 0>
					<#list userList.content as user>
					<tr>
					  <td>
							<a>
								<i class="layui-icon headimg">&#xe612;</i>
								<div style="margin-left:50px;margin-top:0px;">
									${user.username!''}
									<#if user.datastatus == true><i style="color:red;">（已删除）</i></#if>
									<#if user.bindext?? && user.bindext == true && user.extno??>（分机：${user.extno!''}）</#if>
								</div>
								<div title="注册时间" style="margin-left:50px;margin-top:0px;color:#cccccc;font-size:13px;">
									${user.createtime!''}
								</div>
								
							</a>
							
					  </td>
					  <td>${user.uname!''}</td>
					  <td>${user.email!''}</td>
					  <td>${user.mobile!''}</td>
					  <td>
					  	<#if user.agent>
					  		<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
					  	</#if>
					  </td>
					  <#if models?? && models["callcenter"]?? && models["callcenter"] == true>
					  <td>
					  	<#if user.callcenter>
					  		<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
					  	</#if>
					  </td>
					  </#if>
					  <td>
					  	<#if user.usertype?? && user.usertype =="0">
					  		<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
					  	</#if>
					  </td>
					  <td>
					  	<#if user.maxuser?? && user.maxuser ==0>
					  		默认
					  	<#else>
					  		${user.maxuser}
					  	</#if>
					  </td>
					  <td style="white-space:nowrap;" nowrap="nowrap">
					  		<a href="/admin/multitenant/user/edit.html?id=${user.id!''}&p=${p+1}&tenantcode=${tenantcode!''}" data-toggle="ajax" data-width="750" data-height="450" data-title="编辑用户信息">
					  			<i class="layui-icon">&#xe642;</i>
					  			编辑
					  		</a>
					  		<#if !(user.usertype?? && user.usertype == "0") && user.datastatus != true >
					  		<a href="/admin/multitenant/user/delete.html?id=${user.id!''}&p=${p+1}&tenantcode=${tenantcode!''}" style="margin-left:10px;" data-toggle="tip" data-title="请确认是否删除该用户？">
					  			<i class="layui-icon" style="color:red;">&#x1006;</i>
					  			删除
					  		</a>
					  		</#if>
							<a href="javascript:void(0);" style="margin-left:10px;" onclick="loginToUser(this)" data-url="/admin/multitenant/login.html?userid=${user.id!''}&tenantcode=${tenantcode!''}" >
								登录
							</a>
					  </td>
					</tr>
					</#list>
					<#else>
						<div class="ukefu-empty">
							<i class="layui-icon"></i>
							<div style="">
								还没有用户记录
							</div>
						</div>
					</#if>
				  </tbody>
				</table>
			</div> 	   
		</div>
		<div class="row" style="padding:5px;">
			<div class="col-lg-12" id="page" style="text-align:center;"></div>
		</div>
	</div>	
</div>
<script>
	layui.use('layer', function(){
	  var layer = layui.layer;
	  <#if msg?? && msg == 'username_exist'>
		layer.alert('用户名存在，请重新填写', {icon: 2});
	  <#elseif msg?? && msg == 'email_exist'>
		layer.alert('邮件存在，请重新填写', {icon: 2});
	  <#elseif msg?? && msg == 'mobile_exist'>
		layer.alert('手机存在，请重新填写', {icon: 2}); 
	  <#elseif msg?? && msg == 't1'>
		layer.alert('当前用户坐席就绪或对话未结束，不能切换为非坐席', {icon: 2});
	  <#elseif msg?? && msg == 'ext_exist'>
		layer.alert('分机已绑定其他坐席，请选择其他分机', {icon: 2});
	  </#if>
	});  
	layui.use(['laypage', 'layer'], function(){
		  var laypage = layui.laypage
		  ,layer = layui.layer;

		  laypage.render({
				elem: 'page'
				,pages: <#if userList??>${userList.totalPages}<#else>0</#if> //总页数
				,curr:<#if userList??>${userList.number+1}<#else>0</#if>
				,groups: 5 //连续显示分页数
				,jump:function(data , first){
					if(!first){
						location.href = "/admin/multitenant/user/index.html?p="+data.curr+"&tenantcode=${tenantcode!''}" <#if q != '' && q??>+"&q="+${q!''}</#if>;
					}
				}
		   });
		});

	var loginToUser = function(obj){
		console.info("123");
		layer.confirm("确认切换登录到该用户吗？？", {icon: 3, title:'提示'}, function(index){
			layer.close(index);
			var url =  $(obj).attr("data-url");
			$.ajax({
				type : 'GET',
				url : url,
				success : function(res) {
					if(res){
						top.location = res;
					}

				},
				error : function() {
					layer.alert("系统错误", {icon: 2});
				}
			});

		})
	}
</script>